import axios from "axios"
import api from './index'
// 网络请求接口列表
//  在vue3项目中 axios 关于post请求，注意文档类型

// 音乐部分
// ------歌曲分类------
// 发布分类
export  const addSongCategory = async (data={})=> {
     return api.post('/api/songCategory/add',data)
}
export  const listSongCategory = async (data={})=> {
    return api.get('/api/songCategory/list',data)
}
export  const removeSongCategory = async (data={})=> {
    return api.get('/api/songCategory/remove',data)
}
export  const itemsSongCategory = async (data={})=> {
    return api.get('/api/songCategory/items',data)
}

export  const searchSongCategory = async (data={})=> {
    return api.get('/api/songCategory/search',data)
}

// ------歌手------
export  const addSinger = async (data={})=> {
    return api.post('/api/singer/add',data)
}
export  const detailSinger = async (data={})=> {
    return api.get('/api/singer/detail',data)
}

export  const removeSinger = async (data={})=> {
    return api.get('/api/singer/remove',data)
}

export  const itemsSinger = async (data={})=> {
    return api.get('/api/singer/items',data)
}

export  const searchSinger = async (data={})=> {
    return api.get('/api/singer/search',data)
}


// ------歌曲------
export  const addSong = async (data={})=> {
    return api.post('/api/song/add',data)
}
export  const itemsSong = async (data={})=> {
    return api.get('/api/song/items',data)
}
export  const detailSong = async (data={})=> {
    return api.get('/api/song/detail',data)
}
export  const removeSong = async (data={})=> {
    return api.post('/api/song/remove',data)
}
export  const itemsDetail = async (data={})=> {
    return api.get('/api/song/ddtail',data)
}

export  const searchSong = async (data={})=> {
    return api.get('/api/song/search',data)
}

// ------专辑------
export  const addAlbum = async (data={})=> {
    return api.post('/api/album/add',data)
}
export  const itemsAlbum = async (data={})=> {
    return api.get('/api/album/items',data)
}
export  const detailAlbum = async (data={})=> {
    return api.get('/api/album/detail',data)
}
export  const removeAlbum = async (data={})=> {
    return api.post('/api/album/remove',data)
}
export  const searchAlbum = async (data={})=> {
    return api.get('/api/album/search',data)
}
export  const modifyAlbum = async (data={})=> {
    return api.post('/api/album/modify',data)
}

// ------歌单------
export  const addPlayList = async (data={})=> {
    return api.post('/api/playList/add',data)
}
export  const modifyPlayList = async (data={})=> {
    return api.post('/api/playList/modify',data)
}
export  const searchPlayList = async (data={})=> {
    return api.get('/api/PlayList/search',data)
}
export  const detailPlayList = async (data={})=> {
    return api.get('/api/PlayList/detail',data)
}
export  const removePlayList = async (data={})=> {
    return api.get('/api/PlayList/remove',data)
}
export  const itemsPlayList = async (data={})=> {
    return api.get('/api/PlayList/items',data)
}

// 歌单歌曲
export  const addPlayListSong = async (data={})=> {
    return api.post('/api/playListSong/add',data)
}
export  const itemsPlayListSong = async (data={})=> {
    return api.get('/api/playListSong/items',data)
}
export  const removePlayListSong = async (data={})=> {
    return api.get('/api/playListSong/remove',data)
}

// ------轮播图------
export  const addBanner = async (data={})=> {
    return api.post('/api/banner/add',data)
}
export  const listBanner = async (data={})=> {
    return api.get('/api/banner/list',data)
}
export  const removeBanner = async (data={})=> {
    return api.get('/api/banner/remove',data)
}

// 接口：管理员登录
// http://localhost:4000/api/user/signin
export const singin = async (data={})=> {
    return axios.post(
        `${api.url}/api/user/signin`, 
         data,
         {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        }
    )
    .then(response => response.data)
}

// 接口：验证码
// http://localhost:4000/api/verify/test
export const test = async (data={})=> {
    return axios.get(
        `${api.url}/api/verify/test`, 
         {
            params: data
         } 
    )
    .then(response => response.data)
}

// 接口: 用户列表
// http://localhost:4000/api/user/list
export const userList = async (data={})=> {
    return axios.get(`${api.url}/api/user/list`, {params: data}).then(response => response.data)
}
export  const searchUser = async (data={})=> {
    return api.get('/api/user/search',data)
}


// 接口：上传图片
// http://localhost:4000/api/photo/upload
export const photoUpload = async (data={})=> {
    return axios.post(
        `${api.url}/api/photo/upload`, 
         data,
         {
            headers: {
                'Content-Type': 'multipart/form-data'
            }
        }
    )
    .then(response => response.data)
}
// 接口：上传音频
export const audioUpload = async (data={})=> {
    return axios.post(
        `${api.url}/api/audio/upload`, 
         data,
         {
            headers: {
                'Content-Type': 'multipart/form-data'
            }
        }
    )
    .then(response => response.data)
}

// 接口：删除图片
// http://localhost:4000/api/photo/delete
export const photoDelete = async (data={})=> {
    return axios.post(
        `${api.url}/api/photo/delete`, 
         data,
         {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        }
    )
    .then(response => response.data)
}
// 接口：删除音频
export const audioDelete = async (data={})=> {
    return axios.post(
        `${api.url}/api/audio/delete`, 
         data,
         {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        }
    )
    .then(response => response.data)
}

// 接口：获取账号信息
// http://localhost:4000/api/user/info
export const getAccountInfo = async (data={})=> {
    return axios.post(
        `${api.url}/api/user/info`, 
         data,
         {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        }
    )
    .then(response => response.data)
}


// 接口: 使用第三方API获取账号登录IP地址
export const getIpAdress = async ()=> {
    return axios.get(
        // 'https://api.ipify.org?format=json'
        // 发送请求到 ip-api.com 获取IP地址的地理位置信息
        'http://ip-api.com/json'
    )
    .then(response => response.data)
    .catch(error => {
        console.error('无法获取IP地址信息：', error);
    });
}

// 接口：判断用户是否在线
export const userLogged = async (data={})=> {
    return api.post('/api/user/logged',data)
}